// 引入API
import {createRouter,createWebHashHistory} from "vue-router"

// 引入两个页面
// import Home from '../views/Home.vue'
// import About from '../views/About.vue'

//  懒加载引入两个页面
 const Home = () =>import("../views/Home.vue")
 const About = () =>import("../views/About.vue")
 const NotFound = () =>import("../views/404.vue")

//  用户中心页
  const userConter =()=>import('../views/user-center/index.vue');
  // const userProfile =()>=import('../views/user-center/Profile.vue');
  // const userSettings =()>=import('../views/user-center/Settings.vue');

  // 引入product页
  const Product = () =>import("../views/Product.vue")
// 引入vuex
  const VuexPage =()=>import("../views/Vuex.vue")

  // 引入Axios页
  const AxiosTest = ()=> import('../views/AxiosTest.vue')

  

const routes =[
    {
        path:'/',
        redirect:'/home'
    },
   {
     path:'/home',
     name:'home',
     component:Home
   } ,
   {
     path:'/about',
     name:'about',
     component:About
  } ,
  {
    path:'/vuex',
    name:'vuex',
    component:VuexPage
  },
  {
    path:'/product/:id',
    name:'product',
    component:Product
  } ,
  {
    path:'/user',
    name:'userConter',
    component:userConter,
    // redirect:'/user/Profile',
    //     children:[
    //   {
    //     path:'Profile',
    //     name:'profile',
    //     component:userProfile,
    //   },
    //   {
    //     path:'Settings',
    //     name:'Settings',
    //     component:userSettins,
    //   },
    // ]
  } ,
  // {
  //   path:'user',
  //   name:'userConter',
  //   component:userConter,
  //   redirect:'/user/Profile',
  //   children:[
  //     {
  //       path:'Profile',
  //       name:'profile',
  //       component:userProfile,
  //     },
  //     {
  //       path:'Settings',
  //       name:'Settings',
  //       component:userSettins,
  //     },
  //   ]
  // },
  {
    path:'/:pathMatch(.*)*',
    name:'NotFound',
    component:NotFound
  },

  // axios
  {
    path:'/axios-test',
    name:'axiosTest',
    component:AxiosTest
  },
]
// 创建了一个路由的实例化对象
const router =createRouter({
    history:createWebHashHistory(),
    routes
});
router.beforeEach((to,from,next)=>{
  console.log('to',to);
  console.log('from',from);
  next()
})

export default router